package com.ld.security.common.tomcat;

import com.ld.security.common.core.CoreConfig;
import com.ld.security.common.core.modal.chain.ChainManager;
import com.ld.security.common.mybatis.MybatisPlusConfig;
import com.ld.security.common.tomcat.chain.ChainExceptionItem;
import com.ld.security.common.tomcat.config.DruidConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
@Import({MybatisPlusConfig.class,DruidConfiguration.class,CoreConfig.class})
@ComponentScan("com.ld.security.common.tomcat")
public class TomcatAutoConfig {

    @Bean
    public CorsFilter corsFilter() {
        final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
        final CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsFilter(urlBasedCorsConfigurationSource);
    }




}
